const jwt = require("jsonwebtoken");

class LoginController {
  /**颁发token */
  async signToken(ctx, next) {
    const { PRIVATE_KEY } = require("../config/secret");
    // 获取用户信息
    const { name, id } = ctx.user;
    // 颁发token
    const token = jwt.sign({ name, id }, PRIVATE_KEY, {
      expiresIn: 60 * 1000 * 60,
      algorithm: "RS256",
    });
    ctx.body = {
      code: 0,
      data: {
        name,
        token,
      },
      msg: "登录成功!",
    };
  }
}
module.exports = new LoginController();
